<script>
import BaseUrl from "@/http/request/BaseUrl";
import TokenAxios from "@/http/request/TokenAxios";

export default {
  data() {
    return {
      // 当前每页显示多少条数据
      pageSize: 5,
      //分页相关数据
      currentPage: this.$router.currentRoute.query.page ? parseInt(this.$router.currentRoute.query.page) : 1,
      tableData: [],
      total: 0,
      keyword: '',
    }
  },
  methods: {

    search() {
      console.log(this.keyword)

      let page = this.currentPage; // 当前页码
      let url = BaseUrl.ADMIN_ORDER + '/admin/order/search?keyword=' + this.keyword + '&page=' + page;
      console.log(url)
      TokenAxios.get(url).then((response) => {
        let jsonResult = response.data;
        console.log(jsonResult.data)
        if (jsonResult.state == 20000) {
          this.tableData = jsonResult.data.list;
          this.tableData.forEach((item) => {
            if (item.orderState == 0) {
              item.orderState = {
                text: '未支付',
                type: 'danger'
              };
            } else {
              item.orderState = {
                text: '已支付',
                type: 'success'
              };
            }
          })
          console.log(this.tableData)
          this.currentPage = jsonResult.data.currentPage;
          this.pageSize = jsonResult.data.pageSize;
          this.total = jsonResult.data.total;
          this.maxPage = jsonResult.data.maxPage;

        }
      })
    },
    /// 切换分页
    handleCurrentChange(page) {
      if (this.keyword) {
        this.currentPage = page; // 更新当前页码值
        this.search(); // 执行搜索方法
      } else {
        this.$router.replace('?page=' + page);
        this.loadUserList();
      }
    },
    loadUserList() {

      let page = this.$router.currentRoute.query.page;
      if (!page) {
        page = 1;
      }

      let url = BaseUrl.ADMIN_ORDER + '/admin/order?page=' + page;

      TokenAxios.get(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.tableData = jsonResult.data.list;
          this.tableData.forEach((item) => {
            if (item.orderState == 0) {
              item.orderState = {
                text: '未支付',
                type: 'danger'
              };
            } else {
              item.orderState = {
                text: '已支付',
                type: 'success'
              };
            }
          })

          this.currentPage = jsonResult.data.currentPage;
          this.pageSize = jsonResult.data.pageSize;
          this.total = jsonResult.data.total;
        } else {
          let title = '操作失败';
          this.$alert(jsonResult.message, title, {
            confirmButtonText: '确定',
            callback: action => {
            }
          })
        }
      })
    }
  },
  mounted() {
    this.loadUserList();
  }
}
</script>

<template>
  <div>
    <!--面包屑导航区域-->
    <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-bottom: 20px;overflow: hidden">
      <el-breadcrumb-item :to="{ path: '/admin/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
    </el-breadcrumb>

    <el-input
        style="width: 400px"
        placeholder="请输入内容"
        clearable
        v-model="keyword"
    ></el-input>
    <el-button
        slot="append"
        icon="el-icon-search"
        @click="search()"
    ></el-button>

    <el-card style="margin-top: 20px">
      <el-table :data="tableData"
                border stripe
                style="margin-bottom: 20px;overflow: hidden">
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column
            prop="orderNo"
            label="订单编号"
            width="400px">
        </el-table-column>
        <!-- 文章标题 -->
        <el-table-column prop="noteTitle" label="标题" align="center"
                         :show-overflow-tooltip="true"></el-table-column>
        <el-table-column
            prop="buyerId"
            label="用户ID"
            width="120px"
        >
        </el-table-column>
        <el-table-column
            prop="totalPrice"
            label="订单价格(元)"
            width="120">
        </el-table-column>
        <el-table-column
            prop="orderState"
            label="支付状态"
            width="160">
          <template slot-scope="scope">
            <el-tag :type="scope.row.orderState.type">{{ scope.row.orderState.text }}</el-tag>
          </template>
          <!--      <template slot-scope="scope">-->
          <!--        <el-tag type="success"></el-tag>-->
          <!--        <el-tag type="danger"></el-tag>-->
          <!--      </template>-->
        </el-table-column>
        <el-table-column label="支付方式" width="160">
          <template slot-scope="scope">
            <el-tag type="primary">支付宝</el-tag>
          </template>
        </el-table-column>
        <el-table-column
            prop="gmtPay"
            label="支付日期"
            width="220">
        </el-table-column>
        <el-table-column
            prop="createTime"
            label="订单创建时间"
        >
        </el-table-column>
        <!--    <el-table-column-->
        <!--        label="操作"-->
        <!--        width="220">-->
        <!--      <template slot-scope="scope">-->
        <!--        <el-button type="primary" icon="el-icon-edit" size="small" @click="ToEditStatus(scope.row.order_id)"></el-button>-->
        <!--        <el-button type="warning" icon="el-icon-location" size="small" @click="openEditAdd(scope.row.order_id)"></el-button>-->
        <!--        <el-button type="success" icon="el-icon-s-promotion" size="small" @click="expressBox = true" ></el-button>-->
        <!--      </template>-->
        <!--    </el-table-column>-->
      </el-table>
      <!--分页区域-->
      <el-pagination
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :hide-on-single-page="true"
          :page-size="pageSize"
          layout="total, prev, pager, next,jumper"
          :total="total"
          background
      >
      </el-pagination>
    </el-card>
  </div>
</template>


<style scoped>

</style>